package com.cy.shiro;

import org.apache.shiro.authz.Permission;
import org.apache.shiro.authz.permission.PermissionResolver;

/**
 * URL权限字符串解析
 */
public class UrlPermissionResolver implements PermissionResolver{

    @Override
    public Permission resolvePermission(String permissionString) {
        if (permissionString.indexOf(":") != -1){
            String[] str = permissionString.split(":");
            if (str.length != 2)
                throw new RuntimeException("permission string '"+permissionString+"' is incorrect.");
            return new UrlPermission(str[0], str[1]);
        }
        return new UrlPermission(permissionString);
    }
}
